<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Resource extends Model
{
    use SoftDeletes;

    //资源类型
    const TYPE_PAPER = 1;
    const TYPE_BOOK = 2;
    const TYPE_CODE = 3;
    const TYPE_OTHER = 4;

    //算法资源语言
    const LANG_MATLAB = 1;
    const LANG_PYTHON = 2;
    const LANG_C = 3;
    const LANG_C_ADD_ADD = 4;
    const LANG_C_SHARP = 5;
    const LANG_OTHER = 6;

    //COST_TYPE 价值类型
    const COST_TYPE_BY_INTEGRAL = 1; //积分
    const COST_TYPE_BY_D_MONEY = 2; //D币

    protected $fillable = ['file_name', 'origin_name', 'point', 'topic_id', 'user_id', 'file_path', 'download_count','algorithm_lang'];

    public function topic()
    {
        return $this->belongsTo(Topic::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function type_text()
    {
        if(Resource::TYPE_PAPER == $this->type)
        {
            return '文献';
        }
        elseif(Resource::TYPE_BOOK == $this->type)
        {
            return '书籍';
        }
        elseif(Resource::TYPE_CODE == $this->type)
        {
            return '代码';
        }
        elseif(Resource::TYPE_OTHER == $this->type)
        {
            return '其他';
        }
    }
}
